<!--
//
// Trigger.vue
// vue3-element-admin
//
// Created by 区区电脑 on 2023/04/11.
//
-->
<template>
    <div class="Index">
        <!-- 筛选区 -->
<!--        <table-search-bar :config="requestBodyConfig" :model="requestBody" title="" @search="searchClicked" style="padding: unset;border-left: none;box-shadow: none" form-style="padding-top: unset">-->
<!--            <template #button>-->
<!--                <el-button v-permission="permission.add" type="primary" @click="addData">-->
<!--                    <b-icon name="bi-plus" size="20" />-->
<!--                    添加-->
<!--                </el-button>-->
<!--            </template>-->
<!--        </table-search-bar>-->
        <!-- 内容 -->
        <div class="container">
            <!--checkbox设置 :checkbox-config="{trigger: 'row', highlight: true}" -->
            <!--radio设置 :radio-config="{trigger: 'row', highlight: true}" -->
            <vxe-table ref="VXETable" :column-config="{ resizable: false}" :data="state.list" :height="tableHeight" :loading="state.isLoading" :radio-config="{trigger: 'row', highlight: true}" :row-config="{isCurrent: true, isHover: true, keyField: 'id'}" :tree-config="{childrenField: 'children', reserve: true}" border round show-overflow size="small" @current-change="() => {}" @radio-change="() => {}">
                <template #empty>
                    <el-empty :image-size="100" />
                </template>
                <vxe-column fixed="left" title="#" type="seq" width="50" />
                <vxe-column field="updateName" width="140" title="修改项"></vxe-column>
                <vxe-column field="createdTime" width="180" title="操作时间">
                    <template #default="{row}">{{$format.dateTime(row.createdTime)}}</template>
                </vxe-column>
                <vxe-column field="createdUserName" width="120" title="操作人"></vxe-column>
                <vxe-column field="newData" min-width="140" title="新数据"></vxe-column>
                <vxe-column field="oldData" min-width="140" title="旧数据"></vxe-column>
                <vxe-column :resizable="false" field="action" title="操作" :width="$widthColumn(120)">
                    <template #default="{row}">
                        <table-action :actions="[
                            {title: '修改', permission: permission.edit, type: 'primary', ok: editData},
                            {title: '忽略', permission: permission.delete, type: 'danger', ok: deleteData, confirm: '您确定要忽略当前变更记录么?'},
                        ]" :data="row" />
                    </template>
                </vxe-column>
            </vxe-table>
<!--            <div class="page-config">-->
<!--                <vxe-pager v-model:current-page="requestParams.pageIndex" v-model:page-size="requestParams.pageSize" :layouts="['PrevJump', 'PrevPage', 'JumpNumber', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']" :page-sizes="pageConfig.sizes" :total="pageConfig.total" background size="mini" @page-change="onPageChange" />-->
<!--            </div>-->
        </div>
    </div>
</template>

<script setup>
import {ref, reactive, computed, onMounted, inject} from "vue";
import {useStore} from "vuex";
import {useRouter} from "vue-router";
import * as api from "./api.js"

const {$message, $format, $widthColumn} = window;

const detailsInfo = inject("detailsInfo")

const emits = defineEmits();

// 路由
const router = useRouter();
// store
const store = useStore();
const tableHeight = computed(() => store.getters.layoutType === "mobile" ? "" : store.getters.containerHeight - 264)
// 响应式数据
const state = reactive({
    // 表格数据加载中
    isLoading: false,
    // 表格数据
    list: []
})

// 当前页面功能权限
const permission = {
    delete: "Computer:IgnoreIpChangeLog",
};

// 请求query参数
const requestParams = reactive({
    orderCol: "id",
    isDesc: true,
    pageIndex: 1,
    pageSize: 20,
});
// 请求body参数
const requestBody = reactive({
    name: null,
})
// 筛选区域配置
const requestBodyConfig = reactive({
    name: {label: "名称", component: "el-input"},
    // startVersion: {label: "程序版本", component: "el-input"},
    // code: {label: "编号", component: "el-input", inMore: true},
    //sort: {label: "排序", component: "el-select", data: [{name: "1", value: 1}, {name: "2", value: 2}], inMore: true},
    //createdTime: {label: "创建时间", component: "el-date-picker", format: "YYYY-MM-DD", inMore: true},
    //updateTime: {label: "更新时间", component: "el-date-picker-datetime", format: "YYYY-MM-DD HH:mm:ss", inMore: true}
})
// 分页配置
const pageConfig = reactive({
    total: 0,
    sizes: [10, 20, 50, 100, 200]
})

/**
 * 忽略
 * @param id
 * @returns {Promise<void>}
 */
async function deleteData({id}) {
    const {success} = await api.IgnoreIpChangeLog({id})
    if (!success) return
    $message.success("操作成功")
}


// 点击搜索
function searchClicked() {
    console.primary("搜索条件: ", requestBody)
    reload(true);
}

// 查询列表
async function loadList() {
    const params = {
        // ...requestParams,
        computerId: detailsInfo.value.id,
    };
    const body = {
        ...requestBody,
        // programId: detailsInfo.value.id,
        // startVersion: props.version.versionNum,
    };
    state.isLoading = true;
    const {success, data} = await api.GetIpChangeByComputerId(params);
    state.isLoading = false;
    if (!success) return 0;
    // const {items, totalCount} = data;
    // state.list = items;
    // pageConfig.total = totalCount;
    state.list = data || [];
}

// 分页事件
function onPageChange({type}) {
    if (type === "current") {
        loadList()
    }
    if (type === "size") {
        reload(true)
    }
}

// 刷新
function reload(resetPageIndex) {
    if (resetPageIndex) requestParams.pageIndex = 1;
    loadList()
}


onMounted(() => {
    loadList()
})
</script>

<style lang="scss" scoped>
.Index {

    .container {
        background: #fff;
    }
}
</style>
